home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / heaptrk.zip / HEAPTRAK.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  4KB  |  110 lines

  1. Unit HeapTrak;
  2.  
  3. {PROGRAM          :  HEAP TRAK V1.00                                       }
  4. {WRITTEN          :  Sept. 3, 1988                                         }
  5. {AUTHOR           :  Bruce E. Stemplewski                                  }
  6. {ACKNOWLEDGEMENTS :  Kim Kokkonen, TurboPower Software                     }
  7. {             for :  Unit - GrabHeap July 18, 1988                         }
  8.  
  9. {FUNCTION         :  Heap Trak is a handy tool to keep track of just about }
  10. {                    all action that occurs on the heap.                   }
  11.  
  12. {USE              :  To use Heap Trak just apply the USES HeapTrak state-  }
  13. {                    ment in your main program. Heap Trak will create a    }
  14. {                    file called POINTER.LST. If POINTER.LST already exits }
  15. {                    the file will be appended. The date,time and heap     }
  16. {                    origin will be recorded. Any calls to NEW,GETMEM,     }
  17. {                    DISPOSE and FREEMEM will be recorded in the file.     }
  18. {                                                                          }
  19. {                    Ptr Adr  = value of pointer just created              }
  20. {                    Size     = amount of memory allocated                 }
  21. {                    G/F      =                                            }
  22. {                               G = GetMem or New occured                  }
  23. {                               F = FreeMem or Dispose occured             }
  24. {                    Heap Ptr = location of the heap pointer               }
  25. {                    Free Ptr = Location of the free pointer               }
  26. {                    Max Av   = MaxAvail                                   }
  27. {                    Mem Av   = MemAvail                                   }
  28.  
  29. {COMMENT         : You will need GRABHEAP form Turbo Power                 }
  30.  
  31.  
  32.  
  33. Interface
  34.  
  35.    Uses GrabHeap,Hexx,Dates,Times;
  36.  
  37.  
  38.  
  39. Implementation
  40. Var
  41.  
  42.    TextFile : Text;
  43.    OldExit  : Pointer;
  44.  
  45. {$f+}
  46. Procedure HeapTrakExit;
  47. Begin
  48.     ExitProc := OldExit;
  49.    SystemHeapControl;
  50.     Close(TextFile);
  51.  
  52. End;
  53.  
  54.  
  55. Procedure TrakFreeMem(Var P : Pointer; Size : Word); Forward;
  56.  
  57. Procedure TrakGetMem(Var  P : Pointer; Size : Word);
  58. Begin
  59.  
  60.     SystemHeapControl;
  61.     GetMem(P,Size);
  62.     Writeln(TextFile,' $',HexPtr(P),'  ',Size:5,'  G   $',HexPtr(HeapPtr),'   $',HexPtr(FreePtr),
  63.              '   ',FreeMin:6,'   ',MAXAVAIL:6,'    ',MeMAvail:6);
  64.     CustomHeapControl(@TrakGetMem,@TrakFreeMem);
  65.  
  66. End;
  67.  
  68.  
  69. Procedure TrakFreeMem(Var  P : Pointer; Size : Word);
  70. Begin
  71.  
  72.     SystemHeapControl;
  73.     FreeMem(P,Size);
  74.     Writeln(TextFile,' $',HexPtr(P),'  ',Size:5,'  F   $',HexPtr(HeapPtr),'   $',HexPtr(FreePtr),
  75.              '   ',FreeMin:6,'   ',MAXAVAIL:6,'    ',MeMAvail:6);
  76.     CustomHeapControl(@TrakGetMem,@TrakFreeMem);
  77.  
  78. End;
  79.  
  80. {$F-}
  81.  
  82. Begin
  83.  
  84.     OldExit  := ExitProc;
  85.      ExitProc := @HeapTrakExit;
  86.  
  87. {$I-}
  88.    Assign(TextFile,'POINTER.LST');
  89.    Append(TextFile);
  90. {$I+}
  91.  
  92.     If IOResult <> 0 then
  93.       Rewrite(TextFile);
  94.  
  95.  
  96.      CustomHeapControl(@TrakGetMem,@TrakFreeMem);
  97.  
  98.    Writeln(TextFile); Writeln(TextFile);
  99.     Writeln(TextFile,' HEAP TRAK UNIT V1.00   by Bruce E. Stemplewski');
  100.     Writeln(TextFile,'----------------------------------------------------------------------------');
  101.    Writeln(TextFile);
  102.     Writeln(TextFile,'  DATE: ',Date);
  103.     Writeln(TextFile,'  TIME: ',TIME);
  104.     Writeln(TextFile);
  105.    Writeln(TextFile,'  HeapOrg:    $',HexPtr(HeapOrg));
  106.    Writeln(TextFile);
  107.     Writeln(TextFile,'----------------------------------------------------------------------------');
  108.     Writeln(TextFile,'Ptr Adr     Size   G/F   Heap Ptr     Free Ptr  Free Min  Max Av     Mem Av');
  109.     Writeln(TextFile,'----------------------------------------------------------------------------');
  110. End.